package fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;

import com.example.administrator.weipiao.R;
import com.example.administrator.weipiao.VideoActivity;

import java.util.List;

import adapter.MovieAdapter;
import loadresource.Constants;
import loadvideo.DownloadTask;
import loadvideo.Video;
import loadvideo.VideoAdapter;

/**
 * A simple {@link Fragment} subclass.
 */
public class FindFragment extends Fragment implements DownloadTask.OnMovieByPathListener {


    private ListView mLv;
    private VideoAdapter mAdapter;

    public FindFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_find, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mLv = (ListView) view.findViewById(R.id.lv_find);
        DownloadTask task = new DownloadTask(this);
        task.execute(Constants.PAHT3);

        mAdapter = new VideoAdapter(view.getContext());
//        mAdapter = new MovieAdapter(view.getContext());
        mLv.setAdapter(mAdapter);
/*        mLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });*/
        //点击下载视频
//        Button button = (Button) view.findViewById(R.id.button);
//        button.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                startActivity(new Intent(getContext(), VideoActivity.class));
//            }
//        });
    }

    @Override
    public void setOnMovieByPath(List<Video> data) {
        mAdapter.setData(data);
        mAdapter.notifyDataSetChanged();
    }
}
